<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H5页面编辑器 - 登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            min-height: 100vh;
            margin: 0;
            padding: 0;
            display: flex;
        }

        .login-container {
            display: flex;
            width: 100%;
            min-height: 100vh;
            background: #ffffff;
            box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
            animation: slideUp 0.6s ease-out;
        }

        .left-panel {
            flex: 1;
            background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 60px 40px;
            position: relative;
            overflow: hidden;
        }

        .left-panel::before {
            content: '';
            position: absolute;
            top: -30%;
            right: -10%;
            width: 150%;
            height: 150%;
            background: linear-gradient(135deg, rgba(148, 163, 184, 0.03) 0%, rgba(203, 213, 224, 0.03) 100%);
            border-radius: 50%;
            z-index: 1;
        }

        .image-container {
            position: relative;
            z-index: 2;
            text-align: center;
        }

        .main-image {
            width: 280px;
            height: 280px;
            background: linear-gradient(135deg, #e2e8f0, #cbd5e0);
            border-radius: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 100px;
            color: #64748b;
            box-shadow: 0 12px 40px rgba(148, 163, 184, 0.15);
            margin-bottom: 30px;
            animation: float 3s ease-in-out infinite;
            border: 1px solid rgba(226, 232, 240, 0.5);
        }

        @keyframes float {

            0%,
            100% {
                transform: translateY(0px);
            }

            50% {
                transform: translateY(-10px);
            }
        }

        .image-title {
            font-size: 28px;
            font-weight: 600;
            color: #475569;
            margin-bottom: 16px;
        }

        .image-subtitle {
            font-size: 16px;
            color: #64748b;
            line-height: 1.6;
            max-width: 400px;
        }

        .right-panel {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 60px 40px;
            background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
        }

        .login-form-container {
            width: 100%;
            max-width: 400px;
            text-align: center;
        }

        @keyframes slideUp {
            from {
                transform: translateY(30px);
                opacity: 0;
            }

            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        .form-logo {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #e2e8f0, #cbd5e0);
            border-radius: 16px;
            margin: 0 auto 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            color: #64748b;
            box-shadow: 0 4px 16px rgba(148, 163, 184, 0.1);
            border: 1px solid rgba(226, 232, 240, 0.5);
        }

        .form-title {
            font-size: 22px;
            font-weight: 600;
            color: #475569;
            margin-bottom: 8px;
        }

        .form-subtitle {
            font-size: 14px;
            color: #64748b;
            margin-bottom: 24px;
            font-weight: 400;
        }

        .form-group {
            margin-bottom: 18px;
            text-align: left;
        }

        .form-group label {
            display: block;
            font-size: 14px;
            font-weight: 600;
            color: #4a5568;
            margin-bottom: 8px;
        }

        .form-group input {
            width: 100%;
            padding: 10px 14px;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            font-size: 14px;
            background: #ffffff;
            transition: all 0.3s ease;
            font-family: inherit;
            color: #475569;
            min-height: 40px;
        }

        .form-group input:focus {
            outline: none;
            border-color: #cbd5e0;
            box-shadow: 0 0 0 3px rgba(203, 213, 224, 0.1);
            background: #fafbfc;
        }

        .form-group input:hover {
            border-color: #cbd5e0;
            background: #fafbfc;
        }

        .login-btn {
            width: 100%;
            padding: 10px 16px;
            background: linear-gradient(135deg, #cbd5e0, #a0aec0);
            color: #475569;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 8px;
            box-shadow: 0 2px 6px rgba(148, 163, 184, 0.15);
            min-height: 40px;
        }

        .login-btn:hover {
            background: linear-gradient(135deg, #a0aec0, #94a3b8);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(148, 163, 184, 0.2);
        }

        .login-btn:active {
            transform: translateY(0);
        }

        .error-message {
            background: #fef5e7;
            color: #d69e2e;
            padding: 10px 14px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-size: 13px;
            font-weight: 500;
            border: 1px solid #f6e05e;
            display: none;
        }

        .demo-info {
            margin-top: 20px;
            padding: 14px;
            background: #f1f5f9;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
        }

        .demo-info h3 {
            font-size: 14px;
            color: #475569;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .demo-info p {
            font-size: 13px;
            color: #64748b;
            line-height: 1.4;
            margin-bottom: 6px;
        }

        .demo-info .credentials {
            background: #ffffff;
            padding: 10px 14px;
            border-radius: 6px;
            border: 1px solid #e2e8f0;
            margin-top: 10px;
        }

        .demo-info .credentials strong {
            color: #334155;
            font-weight: 600;
        }

        /* 移动端优化 */
        @media (max-width: 768px) {
            .login-container {
                flex-direction: column;
            }

            .left-panel {
                padding: 40px 20px;
                min-height: 40vh;
            }

            .main-image {
                width: 200px;
                height: 200px;
                font-size: 80px;
            }

            .image-title {
                font-size: 24px;
            }

            .image-subtitle {
                font-size: 16px;
            }

            .right-panel {
                padding: 40px 20px;
            }
        }

        @media (max-width: 480px) {
            .left-panel {
                padding: 30px 15px;
                min-height: 35vh;
            }

            .main-image {
                width: 150px;
                height: 150px;
                font-size: 60px;
            }

            .image-title {
                font-size: 20px;
            }

            .image-subtitle {
                font-size: 14px;
            }

            .right-panel {
                padding: 30px 15px;
            }

            .form-group input {
                padding: 10px 14px;
                font-size: 15px;
                min-height: 38px;
            }

            .login-btn {
                padding: 10px 16px;
                font-size: 14px;
                min-height: 38px;
            }
        }
    </style>
</head>

<body>
    <div class="login-container">
        <!-- 左侧图片区域 -->
        <div class="left-panel">
            <div class="image-container">
                <div class="main-image">🎨</div>
                <h1 class="image-title">H5页面编辑器</h1>
                <p class="image-subtitle">专业的移动端页面制作工具<br>让创意触手可及</p>
            </div>
        </div>

        <!-- 右侧登录表单 -->
        <div class="right-panel">
            <div class="login-form-container">
                <!-- <div class="form-logo">✨</div> -->
                <h2 class="form-title">欢迎回来</h2>
                <p class="form-subtitle">请登录您的账户</p>

                <div class="error-message" id="errorMessage"></div>

                <form id="loginForm">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" id="username" name="username" placeholder="请输入用户名" required>
                    </div>

                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" id="password" name="password" placeholder="请输入密码" required>
                    </div>

                    <button type="submit" class="login-btn">登录</button>
                </form>

                <div class="demo-info">
                    <h3>🎯 演示账户</h3>
                    <p>使用以下账户信息登录系统：</p>
                    <div class="credentials">
                        <strong>用户名：</strong>admin<br>
                        <strong>密码：</strong>admin
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', async function (e) {
            e.preventDefault();

            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const errorMessage = document.getElementById('errorMessage');
            const submitBtn = this.querySelector('button[type="submit"]');

            // 隐藏错误信息
            errorMessage.style.display = 'none';

            // 显示加载状态
            const originalText = submitBtn.textContent;
            submitBtn.textContent = '登录中...';
            submitBtn.disabled = true;

            try {
                const response = await fetch('/api/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ username, password })
                });

                const result = await response.json();

                if (result.success) {
                    // 存储登录状态
                    localStorage.setItem('isLoggedIn', 'true');
                    localStorage.setItem('username', result.user.username);
                    localStorage.setItem('currentUser', JSON.stringify(result.user));

                    // 跳转到主页面
                    window.location.href = '/';
                } else {
                    errorMessage.textContent = result.message || '登录失败';
                    errorMessage.style.display = 'block';

                    // 添加错误动画
                    errorMessage.style.animation = 'none';
                    setTimeout(() => {
                        errorMessage.style.animation = 'shake 0.5s ease-in-out';
                    }, 10);
                }
            } catch (error) {
                console.error('登录错误:', error);
                errorMessage.textContent = '网络错误，请重试';
                errorMessage.style.display = 'block';

                // 添加错误动画
                errorMessage.style.animation = 'none';
                setTimeout(() => {
                    errorMessage.style.animation = 'shake 0.5s ease-in-out';
                }, 10);
            } finally {
                // 恢复按钮状态
                submitBtn.textContent = originalText;
                submitBtn.disabled = false;
            }
        });

        // 检查是否已经登录
        if (localStorage.getItem('isLoggedIn') === 'true') {
            window.location.href = '/';
        }

        // 添加错误动画
        const style = document.createElement('style');
        style.textContent = `
            @keyframes shake {
                0%, 100% { transform: translateX(0); }
                25% { transform: translateX(-5px); }
                75% { transform: translateX(5px); }
            }
        `;
        document.head.appendChild(style);
    </script>
</body>

</html>